//
//  planDetailHeader.m
//  XhlTrip
//
//  Created by dllo on 15/8/26.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "planDetailHeader.h"
#import "PlanModel.h"
#import "UIImageView+WebCache.h"
@implementation PlanDetailHeader

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.mage = [[UIImageView alloc] init];
        [self addSubview:self.mage];
        [_mage release];
        
        self.nameLabel = [[UILabel alloc] init];
        [self.mage addSubview:self.nameLabel];
        
        _nameLabel.font = [UIFont fontWithName:@"Verdana-BoldItalic" size:19 * Width];
        _desLabel.font = [UIFont fontWithName:@"Verdana-Italic" size:15 * Width];
        _daysLabel.font = [UIFont fontWithName:@"Verdana-BoldItalic" size:15 * Width];
        _countLabel.font = [UIFont fontWithName:@"Verdana-BoldItalic" size:15 * Width];
        
        [_nameLabel release];
        
        self.daysLabel = [[UILabel alloc] init];
        [self.mage addSubview:self.daysLabel];
        [_daysLabel release];
        
        self.countLabel = [[UILabel alloc] init];
        [self.mage addSubview:self.countLabel];
        [_countLabel release];
        
        self.desLabel = [[UILabel alloc] init];
        [self addSubview:self.desLabel];
        _desLabel.textColor = [UIColor blackColor];
        [_desLabel release];
        
        
        
        _desLabel.numberOfLines = 0;
        _nameLabel.textColor = [UIColor whiteColor];
        _daysLabel.textColor = [UIColor whiteColor];
        _countLabel.textColor = [UIColor whiteColor];
        
  
    }
    return self;
}
#pragma mark - 文字高度自适应
+ (CGFloat)heightWithText:(NSString *)text width:(CGFloat )width
{
    
    CGRect rect = [text boundingRectWithSize:CGSizeMake(width, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont fontWithName:@"Verdana-Italic" size:16 * Width]} context:nil];
    return rect.size.height;
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    self.mage.frame = CGRectMake(0, 0, self.frame.size.width, 180 * Height);
    self.nameLabel.frame = CGRectMake(10 * Width, self.mage.frame.size.height - 60 * Height, self.mage.frame.size.width - 20 * Width, 30 * Height);
    self.daysLabel.frame = CGRectMake(10 * Width, self.mage.frame.size.height - 29 * Height, 40 * Width, 30 * Height);
    self.countLabel.frame = CGRectMake(45 * Width, self.mage.frame.size.height - 29 * Height, 200 * Width, 30 * Height);
    
    
    self.desLabel.frame = CGRectMake(10 * Width, self.mage.frame.size.height + 15 * Height, self.frame.size.width - 20 * Width, self.frame.size.height - self.mage.frame.size.height - 15 * Height);
    
}


- (void)setPlanModel:(PlanModel *)planModel
{
    if (_planModel != planModel) {
        [_planModel release];
        _planModel = [planModel retain];
    }
    self.nameLabel.text = planModel.name;
    NSString *day = [NSString stringWithFormat:@"%@%@", [planModel.plan_days_count stringValue], @"天"];
    self.daysLabel.text = day;
    [self.mage sd_setImageWithURL:planModel.image_url];
    
    NSString *count = [NSString stringWithFormat:@"%@%@", [planModel.plan_nodes_count stringValue], @"旅行地"];
    self.countLabel.text = count;
}



- (void)dealloc
{
    [_planModel release];
    [_nameLabel release];
    [_daysLabel release];
    [_countLabel release];
    [_mage release];
    [_desLabel release];
    [super dealloc];
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
